/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.dao.SmsAlertDao;
import com.minierp.dao.hibernate.BaseDaoImpl;
import com.minierp.model.SmsAlert;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

public class SmsAlertDaoImpl extends BaseDaoImpl implements SmsAlertDao {
	public List getList() {
		String sql = "from com.minierp.model.SmsAlert c where c.enabled=\'Y\' order by c.sequenceCode";
		return this.getHibernateTemplate().find(sql);
	}

	public SmsAlert get(String type) {
		String sql = "from com.minierp.model.SmsAlert c where c.type=\'" + type
				+ "\'";
		List list = this.getHibernateTemplate().find(sql);
		return list.size() == 0 ? null : (SmsAlert) list.get(0);
	}

	public List getReceiverList(long alertId) {
		String sql = "select c,s from com.minierp.model.SmsAlertReceiver c ,com.minierp.model.Staffer s where c.receiverId=s.id and c.alertId="
				+ alertId + " order by s.nameSpell";
		return this.getHibernateTemplate().find(sql);
	}

	public int deleteReceiver(final long id) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "delete com.minierp.model.SmsAlertReceiver where id = :id";
						return new Integer(session.createQuery(hql)
								.setLong("id", id).executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}
}